import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 主页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'icon-gongzuotai' }
    }]
  },
  // 基础信息管理
  {
    path: '/manage-base-info',
    component: Layout,
    // redirect: '/manage-base-info/warehouse',
    name: 'ManageBaseInfo',
    meta: { title: '基础信息管理', icon: 'icon-xinxi' },
    children: [
      {
        path: 'warehouse',
        name: 'Warehouse',
        component: () => import('@/views/manage-base-info/warehouse'),
        meta: { title: '仓库管理', icon: 'icon-yuandianxiao' }
      },
      {
        path: 'warehouse/detail',
        name: 'WarehouseDetail',
        component: () => import('@/views/manage-base-info/components/detail')
      },
      {
        path: 'warehouse/detail/null',
        name: 'WarehouseDetails',
        component: () => import('@/views/manage-base-info/components/detailnull')
      },
      {
        path: 'area',
        name: 'Area',
        component: () => import('@/views/manage-base-info/area'),
        meta: { title: '库区管理', icon: 'icon-yuandianxiao' }
      },
      // {
      //   path: 'area/detail/:keywords',
      //   name: 'Areadetail',
      //   component: () => import('@/views/manage-base-info/components/areadetail')
      // },
      {
        path: 'area/details',
        name: 'Areadetail',
        component: () => import('@/views/manage-base-info/components/areadetail')
      },
      {
        path: 'area/details/null',
        name: 'AreaAdd',
        component: () => import('@/views/manage-base-info/components/areaadd')
      },
      {
        path: 'location',
        name: 'Location',
        component: () => import('@/views/manage-base-info/location'),
        meta: { title: '库位管理', icon: 'icon-yuandianxiao' }
      },
      {
        path: 'location-view',
        name: 'location-view',
        component: () => import('@/views/manage-base-info/location-view'),
        meta: { title: '库位视图', icon: 'icon-yuandianxiao' }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('@/views/manage-base-info/goods'),
        meta: { title: '货品管理', icon: 'icon-yuandianxiao' }
      },
      {
        path: 'goods-type',
        name: 'goods-type',
        component: () => import('@/views/manage-base-info/goods-type'),
        meta: { title: '货品类型管理', icon: 'icon-yuandianxiao' }
      }

    ]
  },
  // 商务管理
  {
    path: '/manage-business',
    component: Layout,
    redirect: '/manage-business/goods-owner',
    name: 'manageBusiness',
    meta: {
      title: '商务管理',
      icon: 'icon-shangwu'
    },
    children: [
      {
        path: 'goods-owner',
        component: () => import('@/views/manage-business/goods-owner'), // Parent router-view
        name: 'goods-owner',
        meta: { title: '货主管理', icon: 'icon-yuandianxiao' }

      },
      {
        path: 'task-picking',
        component: () => import('@/views/manage-business/task-picking'),
        name: 'task-picking',
        meta: { title: '承运商管理', icon: 'icon-yuandianxiao' }
      }
    ]
  },
  // 库内管理
  {
    path: '/manage-storage',
    component: Layout,
    redirect: '/manage-storage/goods-owner',
    name: 'manageStorage',
    meta: {
      title: '库内管理',
      icon: 'icon-cangku'
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/manage-storage/list'), // Parent router-view
        name: 'list',
        meta: { title: '盘点单', icon: 'icon-yuandianxiao' }

      },
      {
        path: 'list-task',
        component: () => import('@/views/manage-storage/list-task'),
        name: 'list-task',
        meta: { title: '盘点任务', icon: 'icon-yuandianxiao' }
      },
      {
        path: '/storage-lose-profit',
        component: () => import('@/views/manage-storage/storage-lose-profit'), // Parent router-view
        name: 'storage-lose-profit',
        meta: { title: '库存损益', icon: 'icon-yuandianxiao' }

      },
      {
        path: 'latest-storage',
        component: () => import('@/views/manage-storage/latest-storage'), // Parent router-view
        name: 'latest-storage',
        meta: { title: '实施库存', icon: 'icon-yuandianxiao' }
      }

    ]
  },
  // 入库管理
  {
    path: '/manage-storage-in',
    component: Layout,
    redirect: '/manage-storage-on/goods-owner',
    name: 'manageStorageIn',
    meta: {
      title: '入库管理',
      icon: 'icon-ruku'
    },
    children: [
      {
        path: 'list-in',
        component: () => import('@/views/manage-storage-in/list-in'), // Parent router-view
        name: 'listIn',
        meta: { title: '入库单', icon: 'icon-yuandianxiao' }

      },
      {
        path: 'task-receive',
        component: () => import('@/views/manage-storage-in/task-receive'),
        name: 'task-receive',
        meta: { title: '收货任务', icon: 'icon-yuandianxiao' }
      },
      {
        path: 'task-add',
        component: () => import('@/views/manage-storage-in/task-add'), // Parent router-view
        name: 'task-add',
        meta: { title: '上架任务', icon: 'icon-yuandianxiao' }

      }

    ]
  },
  // 出库管理
  {
    path: '/manage-storage-out',
    component: Layout,
    redirect: '/manage-storage-out/list-out',
    name: 'manageStorageOut',
    meta: {
      title: '出库管理',
      icon: 'icon-chuku'
    },
    children: [
      {
        path: 'list-out',
        component: () => import('@/views/manage-storage-out/list-out'), // Parent router-view
        name: 'list-out',
        meta: { title: '出库单', icon: 'icon-yuandianxiao' }

      },
      {
        path: 'task-picking',
        component: () => import('@/views/manage-storage-out/task-picking'),
        name: 'task-picking',
        meta: { title: '拣货任务', icon: 'icon-yuandianxiao' }
      },
      {
        path: 'manage-task-transfer',
        component: () => import('@/views/manage-storage-out/manage-task-transfer'), // Parent router-view
        name: 'manage-task-transfer',
        meta: { title: '交接任务', icon: 'icon-yuandianxiao' }

      }

    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
